﻿ rem --- Flashback BASIC Program
 rem --- WARP DRIVE, Starfleet Simulation II
 rem --- Destroy the Industrial complex containing a Gravitic Mine that has you 
 rem --- Trapped in orbit around a Moon, before the Mine pulls you down. 
 
 rem Controls:
 
 rem --- select/reset - change ship/city color schemes
 rem --- bw - Activates Warp Drive, 60 FPS impossible skill level!
 rem --- left difficulty - Advanced/Beginner

 rem ---init section, runs once: -------------
 scrollvirtualworldtoggle=1
 MUSICINDEX=135:player0y=4
 rem g=2
 rem --- queue intro scene:
 gosub 1: g=2:py=77:gosub setmsg
 rem for i = 0 to 239
 rem virtualworld(i)=0:next i
 a=0:gosub loadvirtualworld
  
 rem ---gameloop subroutine, runs every frame:    ---
 rem BYTErowoffset=120
 if g=2 then goto top_message
 t=1-t:rem toggle

 rem --- check for Winner
 if player0y<3 then CXCLR=0:g=2:for i=0 to 255:AUDF0=i:AUDV0=i:next i:BYTErowoffset=0:py=player0y:gosub setmsg:goto top_message
 if SWCHB|%11110111<>255 then scrollvirtualworldtoggle=35:gosub DLI:scrollvirtualworldtoggle=0:goto 0:rem double speed - every frame
 if t=0 then scrollvirtualworldtoggle=35:gosub DLI:scrollvirtualworldtoggle=0:return: rem run this DLI every other frame
 
0 data city 1,4,2,5,3,2,3,1,4,1,1,1,5,2,2,3,1,4,1,4,3,1,4,4,1,1,2,2,3,1,3,4,5,4,4,3,4,5,1,2,4,1,5,2,2,3,1,3,1,1,4,1
1 if g=0 then for j=0 to 7:player1(j)=189:player0(j)=pl(j):next j:BYTErowoffset=120:COLUPF=$50:COLUP0=$b4:COLUBK=0 else goto 3 
 scrollvirtualworldtoggle=1:g=1
 rem =77:goto bounce_off_this_for_intro:rem queue initial intro scene!!!
2 for j=20 to 71:k=j-20:k=city(k)+14:for i=k to 19:vwpixel(j,i,on):next i,j:player0y=96:player0x=84:COLUP1=$74:y=20
3 AUDV0=0:BITIndex=BITIndex+1:missile0x=missile0x+2:data pl 0,224,127,231,252,192:data P 128,0 
 if SWCHB|%11111101<>255 then for i=0 to 9:rowcolors(i)=rowcolors(i)+16:next i
 if SWCHB|%11111110<>255 then for i=0 to 7:player0colors(i)=player0colors(i)+4:next i
fix3
 return

top_message rem ------ MESSAGING SUBSYSTEM (top vertical blank)
 rem g=0 --- can't turn messaging back off here because the bottom blank code will break...
 if bx<>255 then bx=bx+1
65 if var1>0 then VBLANK=2:rem disable TIA output while reguaging display
70 if t=1 then scrollvirtualworldtoggle=32:gosub DLI:scrollvirtualworldtoggle=6:scrollvirtualworldtoggle=0:RAMplayfield(1)=0:RAMplayfield1(1)=0:RAMplayfield2(1)=0:RAMplayfield3(1)=0:RAMplayfield4(1)=0:RAMplayfield5(1)=0:return
77 if SWCHB|%11110111<>255 then VBLANK=2:rem disable TIA output for 30 HZ view with COLOR switch 
 return


bottom_message rem ------- MESSAGING SUBSYSTEM (bottom vertical blank)
 rem can turn messaging back off here:
 rem queue delay so message isn't instantly stopped
 
 if g=2 and joy0fire=1 and bx=255 then for i=120 to 239: virtualworld(i)=0:next i:g=0:NUSIZ0=%00000000:REFP0=0:BITIndex=0:BYTErowoffset=120:scrollvirtualworldtoggle=1:CXCLR=0:var2=0:MUSICINDEX=135:return 
 t=1-t: rem s=1-s:rem toggle - s was getting set to 4 sometimes (also flag var)

50 if t=1 then scrollvirtualworldtoggle=35:gosub DLI:scrollvirtualworldtoggle=0:gosub linkplayer:return
 rem if s=1 then scrollvirtualworldtoggle=35:gosub DLI:scrollvirtualworldtoggle=0:vwpixel(70,8,bindplayer0):gosub linkplayer:return

 if BITIndex=0 and BYTErowoffset=0 and var1=7 then scrollvirtualworldtoggle=1: rem gosub drawlettersonscreen
 rem player0x=MUSICINDEX:player0y=MUSICINDEX*2

 rem s=0
 if var1=0 then BITIndex=BITIndex+1 else var1=var1-1
 if BITIndex=72 and BYTErowoffset=120 then BITIndex=0:BYTErowoffset=0:var1=7
 if BITIndex=72 and BYTErowoffset=0 then BITIndex=0:BYTErowoffset=120

 return

 rem setmsg2

 rem return

 rem -------------------------------------------------------------
drawlettersonscreen rem ------------------------------------------
 rem ---variables----
 rem ---var1 phrase delay
 rem ---m = block index
 rem ---var2 = target block (0 or 1), up to 512 characters, easily expanded
 rem ---i,j,k,l - loop vars 
 rem ---n = tracker controller
 
 rem for i=0 to 239:virtualworld(i)=0:next i:rem clear virtualworld
 MUSICINDEX=135

 rem 20170307 for i=0 to 9:j=i*2:j=j+py:rowcolors(i)=j:j=j-30:player0colors(i)=j:next i


 if var2=1 then goto jmpmsgtypes  
 rem if py<15 then goto jmpmsgtypes: rem and m=255 then m=0:goto jmpmsgtypes

 if py<=36 and m>179 then m=120
 if py<=36 then goto jmpmsgtypes

 if py>=53 and m>59 then m=0
 rem if py>=54 then goto jmpmsgtypes

 if py<=52 and m>119 then m=60


jmpmsgtypes
 

 if m=255 then m=0: rem :var2=var2+1:rem next block, first index
 rem if var2=2 then var2=0:rem only 2 blocks (512 characters)
 rem if var2=2 then var2=1:rem only repeat block2 (512 characters)

 v=2
secondpass if v>2 then v=119:rem second pass for bottom of screen
 for j=20 to 84 step 8:k=j+8
 v=v+1:rem starts at 3...goes 9 accross
 for i=j to k
 rem replace this with lookup
 rem l=j-20:l=l+i:l=l-j:rem l=sprites(l) 
 l=m
 rem if v>119 then l=l+48:rem adjust overlap placement for 2nd pass 
 if var2=0 then l=textdata(l)
 if var2=1 then l=text2dat(l)
 if l>60 and l<97 then l=l+32:rem --- filter uppercase 
 if l=48 then l=111: rem 0 maps to O
 if l=49 then l=105: rem 1 maps to i
 if l=56 then l=98: rem 8 maps to B
 if l=53 then l=115: rem 5 maps to S
 if l=50 then l=123: rem 2 maps to z+1
 if l=51 then l=124: rem 3 maps to z+2
 if l=52 then l=125: rem 4 maps to z+3
 if l=54 then l=126: rem 6 maps to z+4
 if l=55 then l=127: rem 7 maps to z+5
 if l=57 then l=128: rem 9 maps to z+6
 if l=33 then l=i-j:l=sprites2(l):goto handel_exclamation_too : rem handle ! while out of space for chars!

 if l=32 then l=0 else l=l-97:l=l*8:l=l+i:l=l-j:loadplayer1upsidedown(l):l=player1: rem 20170307 inefficient... AFP l=player1(0): rem l=sprites(l)
handel_exclamation_too
 virtualworld(v)=l
 v=v+12
 next i
 m=m+1: rem next letter
 v=v-96:rem 12*8; return to the relative top row 
 v=v-12:rem why? 
 next j
 if v<122 then m=m-3: goto secondpass
 rem 20170307 ---- AFP color changes:
 for i=0 to 17
 j=m+i:j=j+i
 rowcolors(i)=j
 rem player0colors(i)=player0colors(i)+8
 rem !j=player0colors(i)
 rem !j=j+$4e:j=j+i
 rem rowcolors(i)=j
 next i
 rem rowcolors(5)=$4e
 return

 data sprites2  %00000000
 data sprites2a %00000000
 data sprites2b %00001100
 data sprites2c %00001100
 data sprites2d %00001100
 data sprites2e %00000100
 data sprites2f %00000000
 data sprites2g %00001100

 rem --- Message Data can be ASCII codes in BASIC data statements ---
 rem --- or direct text in the special format shown! :) ---
 rem data textdata 104,101,108,108,111,32,119,111,114,108,100,32,116,104,105,115,105,115,97,116,101,115,116,111,102,116,104,101,97,116,97,114,105,50,54,48,48,98,105,103,116,101,120,116,115,99,114,111,108,108,101,114,116,104,97,116,114,117,110,115,97,116,54,48,104,122,111,114,51,48,104,122,44,97,110,100,51,48,102,112,115,119,104,105,108,101,114,117,110,110,105,110,103,97,103,97,109,101,97,110,100,112,108,97,121,105,110,103,116,114,97,99,107,101,114,116,117,110,101,115,111,110,115,116,111,99,107,86,67,83,100,111,117,98,108,101,116,114,117,101,100,111,117,98,108,101,116,114,117,101,32,105,115

 rem ---- Plain text (easier) can be added directly like this:

 

 data textdata    "PRGE 2016 ROCKS"
 data textdata9   "practice this  "
 data textdata8   "game! take aim!"
 data textdata7   "focus your mind"

 data textdata6   "good progress! "
 data textdataB   "You learned to "
 data textdataC   "aim! keep it up"
 data textdatad   "2 win the game!"
 
 data textdataaa  "fantastic aim!!"
 data textdataa9  "You can do it!!"
 data textdataa8  "Concentrate and"
 data textdataa7  "finish the game"

 data textdataa6  "Have you played"
 data textdataaB  "Atari today!msg"
 data textdataaC  "easter-egg fun!"
 data textdataad  "I love writing "
 data textdataae  "BASIC games!U2?"

 data text2dat   "super smooth!  "
 data text2dat9  "you've beaten  "
 data text2dat8  "the game !!!   "
 data text2dat7  "You have Atari "
 data text2dat6  "reflexes and   "
 data text2datB  "video computer "
 data text2datC  "skillz playah !"
 data text2datd  "you are awesome"
 data text2data   "you can react  "
 data text2dat9a  "just like ninja"
 data text2dat8a  "you can catch  "
 data text2dat7a  "arrows by hand!"
 data text2datBa  "you played like"
 data text2dat6a  "William Shatner"
 data text2datCa  "captain James T"
 data text2datda  "Kirk! You are a"
 data text2datea  "StarFighter!!!!"


 rem ASCII translation key: -97 to get 0, * 8 to get index, different for 0123456789 (remapped)
 rem -----------------------------------------------------------------

 rem -----------------------------------------------------------------

17 rem ---gameloop2 subroutine, runs every frame:    --
 if g=2 then goto bottom_message
 if SWCHB|%11110111<>255 then scrollvirtualworldtoggle=8:gosub DLI:scrollvirtualworldtoggle=0:goto 18:rem double speed - every frame
 
 if t=1 then scrollvirtualworldtoggle=8:gosub DLI:scrollvirtualworldtoggle=0:return: rem run this DLI every other frame
18 rem COLUBK=0
 if s=4 then s=0:vwpixel(x,y,flip):player1x=0:player1y=0:AUDC0=y:y=20:AUDF0=4:AUDV0=15:goto 7

 if joy0fire=1 and y>=20 then AUDF0=6:AUDC0=8:AUDV0=15:x=BITIndex+10:i=96-player0y:i=i/10:y=11+i:goto 5: rem fix3


 rem 5 if y<21 then vwpixel(x,y,bindplayer1):j=y-10:y=y+1:COLUP1=M(j):data M $64,$54,$b4,$a4,$32,$44,$c4,$94,$f4,$54,$24,$42
 if y>19 then goto 7
5 vwpixel(x,y,bindplayer1):j=y-10:y=y+1:COLUP1=M(j):data M $64,$54,$b4,$a4,$32,$44,$c4,$94,$f4,$54,$24,$42
 if vwpixel(x,y,poll)>0 then s=4: rem queue event
   
 rem optimize 6 if y<=19 and vwpixel(x,y,poll)>0 then vwpixel(x,y,flip):player1x=0:player1y=0:AUDC0=y:y=20:AUDF0=4:AUDV0=15  
6 rem if y<20 and vwpixel(x,y,poll)>0 then s=4


7 rem if BITIndex>71 then  
 
 if BITIndex<>72 then missile1x=missile1x+1:missile1y=missile1y+3:goto 8
  BITIndex=0
 rem --- make it easier if difficulty is selected (extra 8 passes)
 rem if player0y<90 then player0y=player0y-2 else player0y=player0y-1
 rem -- allow left difficulty to grant several extra orbits at the beginning if set to B (beginner)!
 if SWCHB & %01000000 = 0 and player0y>89 then  player0y=player0y-1 else player0y=player0y-2

 rem if u = 0 and player0y>88 then  player0y=player0y-1 else player0y=player0y-2

 rem 8 if CXP0FB>126 or player0y=1 then CXCLR=0:g=2:for i=0 to 255:AUDF0=i:AUDV0=i:next i:BYTErowoffset=0:py=player0y:gosub setmsg else missile0y=missile0y+2
8 if CXP0FB=130 then CXCLR=0:g=2:py=player0y:gosub setmsg else missile0y=missile0y+2
 return



linkplayer
 if u=0 then player0y=player0y+2 else player0y=player0y-1
 if player0y>96 then u=1
 if player0y<8 then u=0
 if px=0 then player0x=player0x+2 else player0x=player0x-1
 if player0x>140 then px=1:REFP0=255
 if player0x<8 then px=0:REFP0=0

 rem if player0x>136 then player0x=0:player0y=0
 rem if player0x>0 then player1x=player0x+36:player1y=player0y else player1x=0:player1y=0
 rem if player1x>136 then player1x=0:player1y=0
 player1x=player1x+1:player1y=player1y+2
 missile1y=missile1y+3:missile1x=missile1x+1
 missile0y=missile0y+2:missile0x=missile0x+1
 return

setmsg rem ---- init score msg based on position
 m=0:bx=0
 rem -- superfluous, already 0! if py >=53 then m=0

 if py =<52 then m=60
 if py <=36 then m=120
 if py <3 then var2=1:m=0 

 rem gosub setmsg2
 rem if m=0 then j=32 else j=m
 rem for i=0 to 9:rowcolors(i)=j+i:next i
 NUSIZ0=%11111111

 return


19 rem ---KITCHENSINK subroutine, runs when scrollvirtualworldtoggle=1
 if g=2 then gosub drawlettersonscreen

 if SWCHB|%11111101=255 then goto skipselect
 px=1-px:rem toggle cycle colors
skipselect
 
 if px=0 then goto skip_cyclecolors
 for i=0 to 9:rowcolors(i)=rowcolors(i)+16:next i

skip_cyclecolors




rem player0colors $3c,$3c,$3a,$3a,$38,$38,$36,$36
rem rowcolors $72,$62,$52,$54,$56,$46,$44,$42,$42,$46,$44


 rem player0colors 100,255,100,100,200,200,200,200
 rem rowcolors 30,30,30,30,30,30,30,30,70,30

virtualworld
xx..xxxx..x..xxx.x...xxx...x..x.x.x.xxx.x.x.x.x..xx..xx..xx.x.x.x.x.x..xxxx.x.xxx..xx.xx.xx.
xxx..x.xx..xx.x.xx.x.xx.x.xx.x.x.x.x.x.x.x.x.xxx.x.x.x.x.x.x.x..x.xxx.x..x.xxxx.xx..xxxx....
.......................................................................xxxx.................
......................................................................x..x..................
.......................................................................xxxx.................
......................................................................x..x..................
.......................................................................xxxx.................
......................................................................x..x..................
.......................................................................xxxx.................
......................................................................x..x..................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
.......................................................................xxxx.................
......................................................................x..x..................

sprites
........
........
.XXXXXX.
.X....X.
xXXXXXX.
XX....X.
XX....X.
XX....X.

........
........
XXXXXX..
XX...X..
XXXXXXX.
XX....X.
XX....X.
XXXXXXX.

........
........
XXXXXX..
X...XX..
X.......
X.......
X....X..
XXXXXX..

........
........
XXXXXX..
XX....X.
XX....X.
XX....X.
XX....X.
XXXXXX..

........
........
XXXXXXX.
X.......
XXXXXXX.
XX......
XX......
XXXXXXX.

........
........
.XXXXXX.
.XX.....
.XXXXXX.
..X.....
..X.....
..X.....

........
........
XXXXXXX.
XX...XX.
XX......
XX...XX.
XX....X.
XXXXXXX.

........
........
X.....X.
X.....X.
XXXXXXX.
XX....X.
XX....X.
XX....X.

........
........
...XX...
...XX...
...XX...
..XXX...
..XXX...
..XXX...

........
........
.....X..
.....X..
.....X..
.....XX.
XX...XX.
XXXXXXX.

........
........
X..X....
X.X.....
XXXXXX..
XX..XX..
XX..XX..
XX..XX..

........
........
.X......
.X......
.X......
XX......
XX......
XXXXXX..

........
........
XXX.XXX.
X..X.XX.
X....XX.
X....XX.
X.XX.XX.
X.XX.XX.

........
........
XX....X.
X.X...X.
X..X..X.
X...X.X.
X.X..XX.
X.XX..X.

........
........
XXXXXXX.
X.....X.
X....XX.
X....XX.
X....XX.
XXXXXXX.

........
........
XXXXXXX.
X.....X.
XXXXXXX.
XX......
XX......
XX......

........
........
XXXXXXX.
X.....X.
XX....X.
XX....X.
XX..X.X.
XXXXXXX.

........
........
XXXXXx..
X....X..
XXXXXX..
XX...XX.
XX...XX.
XX...XX.

........
........
XXXXXXX.
X.......
XXXXXXX.
......X.
XX....X.
XXXXXXX.

........
........
XXXXXXX.
...XX...
...XX...
...XX...
...XX...
...XX...

........
........
X....XX.
X....XX.
X....XX.
X....XX.
X....XX.
XXXXXXX.

........
........
X....XX.
X....XX.
X....XX.
X....XX.
.X...X..
..XXX...


........
........
XX.XX.X.
XX.XX.X.
XX....X.
XX.X..X.
XXX.X.X.
XX...XX.


........
........
XX...XX.
.XX.XX..
..XXX...
..XXX...
.XX.XX..
XX...XX.

........
........
X.....X.
X.....X.
.X...X..
..XXX...
..XXX...
..XXX...

........
........
XXXXXXX.
X...XX..
...XX...
..XX....
.XX..XX.
XXXXXXX.

........
........
.XXXXXX.
......X.
.XXXXXX.
.X......
.X......
.XXXXXX.

........
........
.XXXXX..
.....X..
.XXXXXX.
.....XX.
.....XX.
.XXXXXX.

........
........
XX......
XX......
XX......
XX...XX.
XXXXXXX.
.....XX.

........
........
XXXXXX..
X....X..
X.......
XXXXXXX.
X.....X.
XXXXXXX.

........
........
XXXXXXX.
XX...X..
....X...
...X....
...X....
...X....

........
........
XXXXXXX.
X....XX.
XXXXXXX.
.....XX.
.....XX.
.....XX.

........
........
..xxx...
.x.x.x..
xxxxxxx.
x.xxx.x.
.x...x..
..xxx...


chiptunes
8, 24, 8, 20, 8
10,24, 10, 20, 8
6, 5, 4, 12, 5
12, 9, 12, 7, 4
8, 24, 8, 20, 8
10,24, 10, 20, 15
8, 24, 8, 20, 8
10,24, 10, 20, 8

8, 24, 8, 20, 4
10,24, 10, 20, 4
8, 24, 8, 20, 4
10,24, 10, 20, 4
8, 24, 8, 20, 4
10,24, 10, 20, 4
8, 24, 8, 20, 2
10,24, 10, 20, 2
8, 24, 8, 20, 15
10,24, 10, 20, 2
8, 24, 8, 20, 2
10,24, 10, 20, 2
8, 24, 8, 20, 2
1,0, 0, 0, 10
0,0, 0, 0, 7
0,0, 0, 0, 7
0,0, 0, 0, 7
0,0, 0, 0, 7
0,0,0,0,0

7,27,7,27,8;---
7,13,7,13,8
7,6,7,6,8
0,0,0,0,4
7,27,7,27,8
7,6,7,6,8
7,6,7,6,8

0,0,0,0,4
7,6,7,6,8
7,6,7,6,8


0,0,0,0,0

7,27,7,27,8
7,6,7,6,8
7,6,7,6,8


0,0,0,0,0


7,13,7,13,14
0,0,0,0,8



0,0,0,0,0

12,3,12,2,4
12,5,12,2,4
0,0,0,0,0
